"use strict";


const Joi = require('joi');
const CheckUtil = require("../utils/check");
const BasicsCtl = require("../basics/clz/basectl");
const HomeImpl = require("../service/home");

class HomeCtl extends BasicsCtl {

  constructor(context) {
    super(context);
    this.homeImpl = new HomeImpl(this.cloud);
  }


  /**
   * 用户登录
   */
  async login() {
    return await this.homeImpl.login(this.params);
  }


  /**
   * 用户授权
   */
  async auth() {
    const rule = {
      nickname: Joi.string().required()
    };
    CheckUtil.validate(rule, this.params);
    return await this.homeImpl.auth(this.params);
  }

  /**
   * 完成第一次
   */
  async finishFirst() {
    return await this.homeImpl.finishFirst(this.params);
  }

  /**
   * 任务列表
   */
  async findTaskList() {
    return await this.homeImpl.findTaskList(this.params);
  }

  /**
   * 商品列表
   */
  async findGoodList() {
    const rule = {
      type: Joi.number().integer().required()
    };
    CheckUtil.validate(rule, this.params);
    return await this.homeImpl.findGoodList(this.params);
  }

  /**
   * 完成任务
   */
  async finishTask() {
    const rule = {
      code: Joi.string().required()
    };
    CheckUtil.validate(rule, this.params);
    return await this.homeImpl.finishTask(this.params);
  }

  /**
   * 加购商品
   */
  async purchase() {
    const rule = {
      id: Joi.number().integer().required()
    };
    CheckUtil.validate(rule, this.params);
    return await this.homeImpl.purchase(this.params);
  }

}
module.exports = HomeCtl;